package com.hhf.stream;

import java.util.stream.Stream;

/**
 * @Author hhf
 * @Date 2024/6/16
 * @Description
 *         //流是并发还是非并发? 跟for的区别?
 *         //流默认非并发,但可以使用parallel()中间操作改为并发
 *         //流的底层也是使用for处理数据
 */
public class StreamDemo3 {

    public static void main(String[] args) {

        long count = Stream.of(1, 2, 3, 4, 5)
                .parallel()             //并发处理
                .filter(element -> {                        //intermediate operation.
                    System.out.println("filter线程: " + Thread.currentThread());
                    System.out.println("正在filter: " + element);
                    return element >= 2;
                })
                .count();// terminal operation.
        System.out.println(count);
    }
}
